import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { accPanelData } from 'src/data/acc_manage/acc_panel_data';
import { WebVisitConst } from "src/consts/web_visit_const";
@Component({})
export default class webApplyAddPanel extends MyVue {
    name: string = 'webApplyAddPanel';
    formData: any;
    footerFlag: boolean = true;
    isEdit: Boolean;

    initData(that?: any): void {
        that.formData = {};
        that.formData.apply_name = getUserInfo().account
        that.formData.create_date = new Date().getTime()

        if (WLStore().state.webVisit.type == "edit") {
            var index = WLStore().state.webVisit.index
            var data = WLStore().state.webVisit.data_list[index]
            that.formData.url = data.url
            that.formData.name = data.web_name
            that.isEdit = true
        } else if (WLStore().state.webVisit.type == "add") {
            that.isEdit = false
        }
    }

    mounted(): void {
    }

    applyAddWeb(): void {
        this.$refs.webVAddForm.validate((valid: Boolean) => {
            if (valid) {
                var sendData = this.formData
                if (WLStore().state.webVisit.type == "edit") {
                    var index = WLStore().state.webVisit.index
                    var data = WLStore().state.webVisit.data_list[index]

                    sendData.web_id = data.id
                    sendData.owner_type = "account"
                    sendData.owner_id = getUserInfo().userId
                    sendData.web_name = sendData.name
                    WLDispatch(WebVisitConst.DispatchWebVVisit, sendData);
                } else if (WLStore().state.webVisit.type == "add") {
                    sendData.apply_id = getUserInfo().userId
                    WLDispatch(WebVisitConst.DispatchWebVAdd, sendData);
                }

            } else {
                WLMessage("必填字段为空,无法申请访问网站", "warning")
                return false;
            }
        })
    }

}